#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
排列3历史开奖数据爬虫
使用极速数据API抓取排列3开奖数据
"""

from typing import List, Dict, Optional
from loguru import logger

from .jisu_spider import JisuLotterySpider


class PL3Spider(JisuLotterySpider):
    """排列3爬虫 - 基于极速数据API"""
    
    def __init__(self):
        super().__init__('pl3')
    
    def validate_numbers(self, numbers: str) -> bool:
        """验证排列3号码格式
        
        Args:
            numbers: 号码字符串，格式如 "1,2,3"
            
        Returns:
            是否有效
        """
        try:
            parts = numbers.split(',')
            if len(parts) != 3:  # 3个号码
                return False
            
            # 验证号码范围（0-9）
            for num in parts:
                if not (0 <= int(num) <= 9):
                    return False
            
            return True
            
        except (ValueError, IndexError):
            return False


if __name__ == '__main__':
    # 测试代码
    from loguru import logger
    logger.add("../logs/pl3_spider.log", rotation="1 day", retention="30 days")
    
    spider = PL3Spider()
    result = spider.run()
    logger.info(f"爬取结果: {result}")